package com.ytjj.qmyx.supplychain.service;

import com.github.pagehelper.PageHelper;
import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.api.CommonResult;
import com.ytjj.qmyx.supplychain.common.model.request.CebUploadReqRequest;
import com.ytjj.qmyx.supplychain.common.model.response.CebUploadReqResponse;
import com.ytjj.qmyx.supplychain.mapper.CebUploadReqMapper;
import com.ytjj.qmyx.supplychain.mapper.entity.CebUploadReq;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Slf4j
@Service
public class CebUploadReqService {
    @Resource
    private CebUploadReqMapper cebUploadReqMapper;

    public CommonPage getCebUploadReqList(CebUploadReqRequest cebUploadReqRequest){
        PageHelper.startPage(cebUploadReqRequest.getPageNum(), cebUploadReqRequest.getPageSize());
        return CommonPage.restPage(cebUploadReqMapper.queryCebUploadReqList(cebUploadReqRequest));
    }

    public CommonResult saveCebUploadReq(CebUploadReq cebUploadReq){
        CebUploadReqResponse cebUploadReqResponse=cebUploadReqMapper.findBySessionId(cebUploadReq.getSessionId());
        if(null!=cebUploadReqResponse){
            return CommonResult.failed("已存在此sessionId！");
        }else{
            cebUploadReqMapper.insert(cebUploadReq);
            return CommonResult.success();
        }
    }

    public CebUploadReqResponse findBySessionId(String sessionId){
        return cebUploadReqMapper.findBySessionId(sessionId);
    }

    public CommonResult updateSignStatus(Integer id, Integer signStatus, String signValue){
        int result=cebUploadReqMapper.updateSignStatus(id,signStatus,signValue);
        if(result>0) {
            return CommonResult.success();
        }else{
            return CommonResult.failed("更新签名失败！");
        }
    }
    public CommonResult updateStatus(Integer id, Integer status, Date uploadTime){
        int result=cebUploadReqMapper.updateStatus(id,status,uploadTime);
        if(result>0) {
            return CommonResult.success();
        }else{
            return CommonResult.failed("更新状态失败！");
        }
    }
}
